﻿using CodeNotes.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using MvcCodeNotes.Models;
using System.IO;

namespace MvcCodeNotes.Controllers
{
    public class MusicController : Controller
    {
        //
        // GET: /Music/

        public ActionResult Index()
        {
            Log.LogNote("music页面Index", "当前时间=" + DateTime.Now.ToString("yyyyMMdd hh:mm:ss"), "error");

            //string url = "http://route.showapi.com/213-4?showapi_sign=3f0c698c4357477ba780198b22f4eeaf&showapi_appid=35037&topid=26";
            //string EncodingStr = "UTF-8";
            //string html = BookFetch.GetHtml(url, EncodingStr);
            //ViewBag.strHtml = html;

            //Dictionary<string, object> dic = new Dictionary<string, object>();

            //JavaScriptSerializer Serializer = new JavaScriptSerializer();
            //dic = Serializer.Deserialize<Dictionary<string, object>>(html);
            //ShowapiModel result = Serializer.Deserialize<ShowapiModel>(html);
            //if (result.showapi_res_body != null && result.showapi_res_body.pagebean != null && result.showapi_res_body.pagebean.songlist != null)
            //{
            //    List<SongModel> songlist = result.showapi_res_body.pagebean.songlist;
            //}
            
         

            return View();
        }

        [HttpPost]
        public JsonResult WriteLog(string msg, TestModel songModel)
        {
            string msg2 = songModel.msg;

            Dictionary<String, String>[] songList = songModel.songList;
            for (int i = 0; i < songList.Length;i++ )
            {
                Dictionary<String, String> dic= songList[i];
            }

                //var sr = new StreamReader(Request.InputStream);
                //var stream = sr.ReadToEnd();
                //JavaScriptSerializer js = new JavaScriptSerializer();
                //var list = js.Deserialize<List<MusicModel>>(songlist);

                Log.LogNote("music页面ready", msg, "error");

            var obj = new
            {
                state = "success"
            };
            return Json(obj);
        }


        //
        // GET: /Music/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Music/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Music/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Music/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Music/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Music/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Music/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }

    public class TestModel
    {        
        public String msg { set; get; }
        public Dictionary<String, String>[] songList { set; get; }  
    }
}
